package com.atguigu.srb.sms.controller;

import com.atguigu.guigu.common.exception.BusinessException;
import com.atguigu.guigu.common.result.R;
import com.atguigu.guigu.common.result.ResultCodeEnum;
import com.atguigu.srb.sms.feign.CoreClient;
import com.atguigu.srb.sms.service.SmsService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController

@RequestMapping("/api/sms")
public class ApiSmsController {
    @Resource
    SmsService smsService;
    @Resource
    CoreClient coreClient;
    @ApiOperation("测试远程调用")
    @GetMapping("test")
    public R test(){// 0:注册  1：登录  2：充值.....
        coreClient.test1("hehe");
        return R.ok();
    }
    @ApiOperation("测试远程调用2")
    @GetMapping("test2")
    public R test2(){// 0:注册  1：登录  2：充值.....
        coreClient.test2("hehe","haha");
        return R.ok();
    }
    @ApiOperation("测试远程调用3")
    @GetMapping("test3")
    public R test3(){// 0:注册  1：登录  2：充值.....
        coreClient.test3(new BusinessException(1,"ceshi"));
        return R.ok();
    }

    @ApiOperation("测试远程调用4")
    @GetMapping("test4")
    public R test4(){// 0:注册  1：登录  2：充值.....
        coreClient.test4(R.setResult(ResultCodeEnum.CALLBACK_PARAM_ERROR));
        return R.ok();
    }

    @ApiOperation("发送短信")
    @GetMapping("sendMsg/{mobile}/{type}") //type表示本次发送短信的类型，借此选择发送短信的模板
    public R sendMsg(@PathVariable("mobile")String mobile,
                     @ApiParam(value = "短信类型: 0:注册  1：登录  2：充值")
                     @PathVariable("type")Integer type){// 0:注册  1：登录  2：充值.....
        smsService.sendMsg(mobile,type);
        return R.ok();
    }
}
